package com.shj.controller;

import com.shj.entity.SysChronicdis;
import com.shj.service.SysChronicdisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/system/chronicdis")
public class SysChronicdisController {

    @Autowired
    private SysChronicdisService sysChronicdisService;

    @RequestMapping("/list")
    public String findAll(Model model) {
        List<SysChronicdis> list = sysChronicdisService.findAll();
        model.addAttribute("list", list);
        return "chronicdis/chronicdis_list";
    }

    @RequestMapping("/openAdd")
    public String openAdd(Model model) {
        return "chronicdis/chronicdis_add";
    }

    @RequestMapping("/add")
    public String add(Model model, SysChronicdis sysChronicdis) {
        sysChronicdisService.add(sysChronicdis);
        return findAll(model);
    }

    @RequestMapping("/openEdit")
    public String openEdit(Model model, String id){
        SysChronicdis sysChronicdis = sysChronicdisService.findById(id);
        model.addAttribute("chronicdis", sysChronicdis);
        return "chronicdis/chronicdis_edit";
    }

    @RequestMapping("/edit")
    public String edit(Model model, SysChronicdis sysChronicdis) {
        sysChronicdisService.edit(sysChronicdis);
        return findAll(model);
    }

    @RequestMapping("/delete")
    public String delete(Model model, String id){
        sysChronicdisService.delete(id);
        return findAll(model);
    }
}
